package util;

import entity.*;
import java.util.HashMap;
import java.util.Map;

public class EntityConverter {
    // 歌曲转换
    public static Map<String, Object> songToMap(Song song) {
        if (song == null) return null;
        
        Map<String, Object> map = new HashMap<>();
        map.put("id", String.valueOf(song.getSongId()));
        map.put("title", song.getTitle());
        map.put("artist", song.getArtist());
        map.put("url", song.getMusicFilePath());
        map.put("lrc", song.getLyricFilePath());
        map.put("cover", song.getCoverFilePath());
        map.put("duration", String.valueOf(song.getDuration()));
        return map;
    }

    // 歌单转换
    public static Map<String, Object> playlistToMap(Playlist playlist, String creatorName, boolean isFavorited) {
        if (playlist == null) return null;
        
        Map<String, Object> map = new HashMap<>();
        map.put("id", String.valueOf(playlist.getPlaylistId()));
        map.put("name", playlist.getName());
        map.put("description", playlist.getDescription());
        map.put("cover", playlist.getCoverFilePath());
        map.put("userId", String.valueOf(playlist.getCreatorId()));
        map.put("userName", creatorName);
        map.put("isFavorited", isFavorited);
        return map;
    }

    // 用户信息转换
    public static Map<String, Object> userToMap(User user) {
        if (user == null) return null;
        
        Map<String, Object> map = new HashMap<>();
        map.put("userId", user.getUserId());
        map.put("username", user.getUsername());
        map.put("backgroundImage", user.getBackgroundImage());
        map.put("backgroundColor", user.getBackgroundColor());
        return map;
    }

    // 用户基本信息转换
    public static Map<String, Object> userToBasicMap(User user) {
        if (user == null) return null;
        
        Map<String, Object> map = new HashMap<>();
        map.put("userId", user.getUserId());
        map.put("username", user.getUsername());
        return map;
    }
}